package com.goodving.guli.fragment;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;

import com.androidquery.AQuery;
import com.goodving.guli.R;
import com.goodving.guli.model.DailyStats;
import com.goodving.guli.model.TimeLineModel;
import com.goodving.guli.model.WeatherInfoModel;
import com.goodving.guli.service.StepMessage;
import com.goodving.guli.utility.C1057l;
import com.goodving.guli.utility.C1102e;
import com.goodving.guli.view.StatsCircleView;

/**
 * Created by Administrator on 2015-11-17.
 */
public class PageViewListFragment extends Fragment {
    public static String TAG;
    private AQuery mAQuery;
    private DailyStats mDailyStats;
    private ListView mListView;
    private C1057l mListViewAdapter;
    private int mPosition;
    private StatsCircleView mStatsCircleView;
    private WeatherInfoModel mWeatherInfoModel;

    /* renamed from: cn.ledongli.ldl.fragment.PageViewListFragment.1 */
    class C13511 implements C1102e {
        final /* synthetic */ DailyStats val$mDailyStats;

        C13511(DailyStats dailyStats) {
            this.val$mDailyStats = dailyStats;
        }

        public void onSuccess(Object obj) {
            if (obj == null) {
                try {
                    PageViewListFragment.this.updateActivityList(false);
                    return;
                } catch (Exception e) {
                    PageViewListFragment.this.updateActivityList(false);
                    e.printStackTrace();
                    return;
                }
            }
            PageViewListFragment.this.mWeatherInfoModel = (WeatherInfoModel) obj;
            PageViewListFragment.this.mStatsCircleView.updateStatsCircle(PageViewListFragment.this.mWeatherInfoModel, PageViewListFragment.this.mListViewAdapter.f3776b.size(), this.val$mDailyStats);
            PageViewListFragment.this.updateActivityList(true);
        }

        public void onFailure(int i) {
            PageViewListFragment.this.updateActivityList(false);
        }
    }

    public PageViewListFragment() {
        this.mPosition = -1;
    }

    static {
        TAG = PageViewListFragment.class.getName();
    }

    public static PageViewListFragment newInstance(int i, DailyStats dailyStats) {
        PageViewListFragment pageViewListFragment = new PageViewListFragment();
        pageViewListFragment.mDailyStats = dailyStats;
        pageViewListFragment.mPosition = i;
        return pageViewListFragment;
    }

    public void updateStepNotification(StepMessage stepMessage) {
        if (this.mStatsCircleView != null) {
            this.mStatsCircleView.updateStepNotification(stepMessage);
        }
    }

    public void updateStatus(DailyStats dailyStats) {
        if (dailyStats != null) {
            Log.e(TAG, "=============updateStatus================");
            this.mDailyStats = dailyStats;
            if (this.mStatsCircleView != null) {
                this.mStatsCircleView.updateStatsCircle(dailyStats);
            }
            updateTimeLine();
        }
    }

//    public String saveShareImage() {
//        return this.mStatsCircleView.saveShareCircle();
//    }

    public void createFragment() {
        if (this.mPosition >= 0) {
            DailyStats dailyStats = this.mDailyStats;
            dailyStats.setStepCnt(1000);//TBD just for debug
            this.mListView.setTag("listView");
            this.mStatsCircleView = new StatsCircleView(getActivity(), dailyStats);
            Log.e(TAG, "----------------createFragment-----------------");
            this.mListView.addHeaderView(this.mStatsCircleView);
//            this.mListView.addFooterView(LayoutInflater.from(getActivity()).inflate(R.layout.pageview_footer, null));
            updateTimeLine();
        }
    }

    public void onPause() {
        super.onPause();
//        MobclickAgent.onPageEnd("PageViewFragment");
    }

    public void onResume() {
        super.onResume();
        Log.e(TAG, "=============onResume================");
//        MobclickAgent.onPageStart("PageViewFragment");
    }

//    private void checkRGMGenerate() {
//        long j = C1481u.m12082d().getLong(C1465g.az, 0);
//        if (j > 0) {
//            double longBitsToDouble = Double.longBitsToDouble(j);
//            ArrayList a = C1294p.m11531a(this.mDailyStats);
//            int i = 0;
//            for (int i2 = 0; i2 < a.size(); i2++) {
//                if (longBitsToDouble == ((double) ((Activity) a.get(i2)).m8574r().getTime()) / 1000.0d) {
//                    i = i2;
//                }
//            }
//            this.mListView.setScrollContainer(true);
//            this.mListView.setSelection(i);
//        }
//    }

    public View onCreateView(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
        View inflate = layoutInflater.inflate(R.layout.activity_pageview, viewGroup, false);
        Log.e(TAG, "=============onCreateView================");
        this.mAQuery = new AQuery(inflate);
        this.mListView = ((AQuery) this.mAQuery.id((int) R.id.listview_activity)).getListView();
        return inflate;
    }

    public void onActivityCreated(Bundle bundle) {
        super.onActivityCreated(bundle);
        Log.e(TAG, "=============onActivityCreated================");
        createFragment();
    }

    private void updateTimeLine() {
        TimeLineModel timeLineModel = new TimeLineModel();
        Log.e(TAG, "=============updateTimeLine================");
//        timeLineModel.mActivityList = C1294p.m11531a(this.mDailyStats);
//        timeLineModel.mPBWeightList = C1294p.m11535b(this.mDailyStats);
        if (timeLineModel != null) {
            if (this.mListViewAdapter == null) {
                this.mListViewAdapter = new C1057l(getActivity(), this.mDailyStats, this.mAQuery, timeLineModel.mActivityList, null);//null = timeLineModel.mPBWeightList
            } else {
                this.mListViewAdapter.f3776b = timeLineModel.mActivityList;
//                this.mListViewAdapter.f3777c = timeLineModel.mPBWeightList;
            }
            if (this.mWeatherInfoModel == null) {
                updateWeatherInfo(this.mDailyStats);
            } else {
                if (this.mStatsCircleView != null) {
                    this.mStatsCircleView.updateStatsCircle(this.mWeatherInfoModel, this.mListViewAdapter.f3776b.size(), this.mDailyStats);
                }
                updateActivityList(true);
            }
            if (this.mListView == null) {
                this.mListView = null;
            } else {
                this.mListView.setAdapter(this.mListViewAdapter);
                this.mListViewAdapter.notifyDataSetChanged();
            }
        }
    }

    private void updateStatsCircle() {
    }

    private void updateWeatherInfo(DailyStats dailyStats) {
//        C1294p.m11534a(dailyStats, new C13511(dailyStats));
    }

    public void updateActivityList(boolean z) {
        if (this.mListViewAdapter != null) {
            this.mListViewAdapter.m7611a(z);
            this.mListViewAdapter.notifyDataSetChanged();
        }
    }
}
